package com.zsq.thread.test2;

/**
 * @author : zhang sq
 * @date : 2019/12/25 21:36
 **/
//一个同步方法可以调用另外一个同步方法,一个线程已经拥有某个对象的锁,再次申请的时候仍然会得到
 //  该对象的锁,也就是说synchronized获得的锁是可重入的
public class Sync5 {
    
    public static void main(String[] args) {
        Sync5 sync4=new Sync5();
        sync4.m1();
    }


    private synchronized void m1() {
        System.out.println(Thread.currentThread().getName() + "m1 Start");
        try {
            Thread.sleep(4000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        m2();
        System.out.println(Thread.currentThread().getName() + "m1 End");
    }

    private synchronized  void m2() {
        System.out.println(Thread.currentThread().getName() + "m2 Start");
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "m2 End");
    }
}
